package com.woniuxy.carlife.controller;


import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.domain.ServiceAppraiseTag;
import com.woniuxy.carlife.dto.AllAppraiseWithId;
import com.woniuxy.carlife.dto.AppraiseTagDto;
import com.woniuxy.carlife.param.SaveAppraiseTagParam;
import com.woniuxy.carlife.service.ServiceAppraiseTagService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author fx
 * @ClassName:ServiceAppraiseTagController
 * @Description: 门店服务评价标签控制类
 * @date 2021/4/6 20:00
 **/

@RestController
@RequestMapping("/serviceAppraiseTag")
@Slf4j
@Api(tags = "门店评论标签接口信息")//用于描述接口类的相关信息，作用于类上
public class ServiceAppraiseTagController {

    @Resource
    private ServiceAppraiseTagService service;

    /**
     * 功能描述〈根据门店id增加门店评论标签信息〉
     * @author:fx
     * @param: @param null:
     * @return:
     * @Date 2021/4/10 10:16
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "根据门店id增加门店评论标签信息",notes = "<span style='color:red;'>根据门店id增加门店评论标签信息</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "新增成功"),
            @ApiResponse(code=20001,message = "新增失败"),
            @ApiResponse(code=30001,message = "参数错误")
    })
    @PostMapping("/merchantmanage/storetag")
    public Result saveCommentTagStatusByStoreId(@RequestBody @ApiParam SaveAppraiseTagParam appraiseTag){
        log.info("saveCommentTagStatusByStoreId开始:参数：{}",appraiseTag);
        //判断参数
        if (appraiseTag.getCommentTagContent()==null||
            appraiseTag.getCommentTagContent().trim().length()==0||
            appraiseTag.getStoreId()==null||
            appraiseTag.getStoreId()<=0){
            log.info("saveCommentTagStatusByStoreId结束:结果：{}","添加标签失败");
            return new Result(false, StatusCode.PARAMERROR,"输入参数错误");
        }
        Integer integer = service.saveCommentTagStatusByStoreId(appraiseTag);
        if (integer==1){
            log.info("saveCommentTagStatusByStoreId结束:结果：{}","添加标签成功");
            return new Result(true, StatusCode.OK,"添加标签成功");
        }else if (integer==0){
            log.info("saveCommentTagStatusByStoreId结束:结果：{}","添加标签失败");
            return new Result(false, StatusCode.ERROR,"添加标签失败");
        }else{
            log.info("saveCommentTagStatusByStoreId结束:结果：{}","已存在标签");
            return new Result(false, StatusCode.ERROR,"添加标签失败，标签已存在");
        }

    }

    /**
     * 功能描述〈根据门店id查看指定门店所有的评论标签信息〉
     * @author:fx
     * @param: @param null:
     * @return:
     * @Date 2021/4/10 10:22
     * @throws
     */
    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "根据门店id查看指定门店所有的评论标签信息",notes = "<span style='color:red;'>根据门店id查看指定门店所有的评论标签信息</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "查询门店标签成功"),
            @ApiResponse(code=20001,message = "没有查询到门店标签信息"),
            @ApiResponse(code=30001,message = "参数错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId",value = "门店",dataType = "Integer",paramType = "query",example = "1"),
    })
    @GetMapping("/merchantmanage/storetags")
    public Result findAllApprasieTagByStoreId(Integer storeId){
        log.info("findAllApprasieTagByStoreId开始:参数：{}",storeId);
        if (storeId==null||storeId<=0){
            log.info("findAllApprasieTagByStoreId结束:返回：{}","输入参数错误，为空或者小于1");
            return new Result(false, StatusCode.PARAMERROR,"输入参数错误");
        }
        List<AppraiseTagDto> allApprasieTagByStoreId = service.findAllApprasieTagByStoreId(storeId);
        if (ObjectUtils.isEmpty(allApprasieTagByStoreId)){
            log.info("findAllApprasieTagByStoreId结束:返回：{}","没查到数据");
            return new Result(false, StatusCode.NULLDATA,"查询失败。没查到数据");
        }
        log.info("findAllApprasieTagByStoreId结束:返回：{}",allApprasieTagByStoreId);
        return new Result(true, StatusCode.OK,"查询门店标签成功",allApprasieTagByStoreId);
    }

    /**
     * 功能描述〈根据评论标签id改变评论标签被选择的次数redis〉
     * @author:fx
     * @param: @param null:
     * @Date 2021/4/10 10:31
     * @throws
     */
    @ApiOperation(value = "根据评论标签id改变评论标签被选择的次数",notes = "<span style='color:red;'>根据评论标签id改变评论标签被选择的次数</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "修改标签选择次数成功"),
            @ApiResponse(code=20001,message = "修改标签选择次数失败"),
            @ApiResponse(code=30001,message = "参数错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appraiseTagId",value = "被选中的标签id",dataType = "List<Integer>",paramType = "query",example = "[1]"),
    })
    @PutMapping("/ordinary/tagsnum")
    public Result updateAppraiseTagByTagId(List<Integer> appraiseTagId){
        log.info("updateAppraiseTagByTagId开始:参数：{}",appraiseTagId);
        if (appraiseTagId.size()<=0){
            log.info("updateAppraiseTagByTagId结束:返回：{}","参数没有值");
            return new Result(false, StatusCode.PARAMERROR,"输入参数错误");
        }
        //查看执行结果
        boolean b = service.updateAppraiseTagByTagId(appraiseTagId);
        if (b){
            log.info("updateAppraiseTagByTagId结束:返回：{}","修改标签选择次数成功");
            return new Result(true, StatusCode.OK,"修改标签选择次数成功");
        }
        log.info("updateAppraiseTagByTagId结束:返回：{}","修改标签选择次数失败");
        return new Result(false, StatusCode.ERROR,"修改标签选择次数失败");
    }

    /**
     * 功能描述〈根据评论标签id改变标签状态为未使用，每次改变一个〉
     * @author:fx
     * @param: @param null:
     * @return:
     * @Date 2021/4/10 10:34
     * @throws
     */
    @ApiOperation(value = "根据评论标签id改变标签状态为未使用",notes = "<span style='color:red;'>根据评论标签id改变标签状态为未使用</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "修改标签状态成功"),
            @ApiResponse(code=20001,message = "修改标签状态失败"),
            @ApiResponse(code=30001,message = "参数错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appraiseTagId",value = "被选中的标签id",dataType = "Integer",paramType = "query",example = "1"),
    })
    @PutMapping("/merchantmanage/tagsnot")
    public Result updateAppraiseTagStatusByTagId(Integer appraiseTagId){
        log.info("updateAppraiseTagStatusByTagId开始:参数：{}",appraiseTagId);
        //判断参数是否有误
        if (appraiseTagId==null||appraiseTagId<=0){
            log.info("updateAppraiseTagStatusByTagId结束:返回：{}","参数为空或小于1");
            return new Result(false, StatusCode.PARAMERROR,"输入参数错误");
        }
        boolean b = service.updateAppraiseTagStatusByTagId(appraiseTagId);
        if (b){
            log.info("updateAppraiseTagStatusByTagId结束:返回：{}","修改标签状态成功");
            return new Result(true, StatusCode.OK,"修改标签状态成功");
        }
        log.info("updateAppraiseTagStatusByTagId结束:返回：{}","修改标签状态失败");
        return new Result(false, StatusCode.ERROR,"修改标签状态失败");
    }

    /**
     * 功能描述〈根据门店id查询指定门店评论标签状态为已使用的标签〉
     * @author:fx
     * @param: @param null:
     * @return:
     * @Date 2021/4/10 10:37
     * @throws
     */
    @ApiOperation(value = "根据门店id查询指定门店评论标签状态为已使用的标签",notes = "<span style='color:red;'>根据门店id查询指定门店评论标签状态为已使用的标签</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "查询已使用标签成功"),
            @ApiResponse(code=20001,message = "查询已使用标签失败"),
            @ApiResponse(code=30001,message = "参数错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId",value = "门店id",dataType = "Integer",paramType = "query",example = "1"),
    })
    @GetMapping("statususe")
    public Result findAllAppraiseTagByStoreIdWithStatusIsING(Integer storeId){
        log.info("findAllAppraiseTagByStoreIdWithStatusIsING开始:参数：{}",storeId);
        if (storeId==null||storeId<=0){
            log.info("findAllAppraiseTagByStoreIdWithStatusIsING结束:返回：{}","参数为空或小于1");
            return new Result(false, StatusCode.PARAMERROR,"输入参数错误");
        }
        List<AppraiseTagDto> allAppraiseTagByStoreIdWithStatusIsING =
                service.findAllAppraiseTagByStoreIdWithStatusIsING(storeId);
        if (ObjectUtils.isEmpty(allAppraiseTagByStoreIdWithStatusIsING)){
            log.info("findAllAppraiseTagByStoreIdWithStatusIsING结束:返回：{}","查询失败，没有查找到数据");
            return new Result(false, StatusCode.NULLDATA,"查询失败，没有查找到数据");
        }
        log.info("findAllAppraiseTagByStoreIdWithStatusIsING结束:返回：{}",allAppraiseTagByStoreIdWithStatusIsING);
        return new Result(true, StatusCode.OK,"查询已使用标签成功",allAppraiseTagByStoreIdWithStatusIsING);
    }
}

